Repository navigation
fix(grid): structural styles, scrolling and filter row in a shadow root - #18097
Open
rkaraivanov wants to merge 2 commits into
Open
rkaraivanov wants to merge 2 commits into
rkaraivanov wants to merge 2 commits into
Conversation
The grid's structural stylesheet was adopted by the document only, so a grid in a shadow root (a custom element or a ShadowDom component) had no layout. IgxStylesRegistrar.register() takes an optional host and also adopts the sheet into the host's shadow root. The grid registers in ngOnInit, once its element is attached, also inside @if or @for. Closes #17859 Part of #18088 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The vertical scroll handler runs after a throttle and the filter row input handler after a debounce. In a shadow root the browser clears the event target when the dispatch ends, so reading event.target threw and the rows did not follow the scrollbar or the filter was not applied. The for-of directives read the scroll element and the filter row reads its input element instead. Closes #17860 Part of #18088 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
rkaraivanov
requested review from
mddragnev and
simeonoff
and
a balanced review from Copilot
December 4, 2026 11:42
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The example calls inject() inside ngOnInit, outside Angular’s injection context, causing NG0203 when copied into a component.
1 open issue
What changed in this PR
Fixes grid layout, scrolling, and filtering inside shadow roots for Angular components and Angular Elements, addressing #17859 and #17860.
Changes:
- Adopts structural styles into the grid’s shadow root while retaining document styles.
- Reads scroll and filter values from elements rather than deferred event targets.
- Adds regression tests and changelog entries.
| File | Description |
|---|---|
projects/igniteui-angular/test-utils/grid-samples.spec.ts |
Adds a shared shadow-root grid fixture. |
projects/igniteui-angular/grids/grid/src/grid.component.spec.ts |
Tests shadow-root styling and throttled scrolling. |
projects/igniteui-angular/grids/grid/src/grid-filtering-row.spec.ts |
Tests filtering inside a shadow root. |
projects/igniteui-angular/grids/grid/src/grid-base.directive.ts |
Registers styles during initialization with the grid host. |
projects/igniteui-angular/grids/core/src/filtering/base/grid-filtering-row.component.ts |
Reads the filter input directly. |
projects/igniteui-angular/directives/src/directives/for-of/for_of.directive.ts |
Reads positions from scroll elements. |
projects/igniteui-angular/core/src/services/styles/styles-registrar.service.ts |
Adds host-aware shadow-root stylesheet adoption. |
projects/igniteui-angular/core/src/services/styles/styles-registrar.service.spec.ts |
Tests host-aware stylesheet registration. |
projects/igniteui-angular-elements/src/app/custom-strategy.spec.ts |
Tests structural styles for Elements in shadow roots. |
CHANGELOG.md |
Documents fixes and the optional registrar host parameter. |
Review effort: Balanced
Comment on lines
+60
to
+62
| * public ngOnInit(): void { | ||
| * inject(IgxStylesRegistrar).register(STYLES_ID, MY_COMPONENT_CSS, this.elementRef.nativeElement); | ||
| * } |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Closes #17859, closes #17860
Description
IgxStylesRegistrar.register()takes an optionalhost. The sheet is still adopted by the document. Whenhost.getRootNode()is aShadowRootthat does not have the sheet yet, the same sheet is adopted by that shadow root too.IgxGridBaseDirectiveregisters its structural sheet inngOnInitwith its element, instead of in the constructor without one.retain()stays in the constructor.IgxForOfDirective.onScroll/onHScrollandIgxGridForOfDirective.onScrollread the scroll position from their scroll element instead ofevent.target.IgxGridFilteringRowComponentreads its input element instead ofevent.targetwhen the debounced input is handled.Motivation / Context
#18088 tracks a grids release that works in a shadow root and uses
igniteui-i18n-core2. App Builder exports Web Components views as Lit components with an open shadow root, and they stay on grids 6.1. This pull request fixes the two causes:IgxStylesRegistraradopted the grid's structural sheet by the document only, so a grid in a shadow root had no layout. Angular already copies the<style>elements of the other components into a shadow root that holds a root component, so only the registrar's sheet was missing. The same happens for a grid in a component withViewEncapsulation.ShadowDom.event.targettonullfor an event in a shadow tree, so scrolling threw and the filter row did not filter.Notes for review:
ngOnInitbecause a grid inside@ifor@foris not attached in its constructor. With the host passed in the constructor, the shadow root does not get the sheet (checked with the spec below).document.body.IgxForOfScrollSyncService), so their scroll element is the event's target.core()styles, such as the virtual scrollbar.Not fixed here: when any root component in a shadow root is destroyed, Angular removes the
<style>elements of all components from that root. In Elements this happens when oneigc-*element, such as anigc-column, is removed. It is tracked in a separate issue.Type of Change (check all that apply):
Component(s) / Area(s) Affected:
Grid, Tree Grid, Hierarchical Grid, Pivot Grid,
igxFor,IgxStylesRegistrar, ElementsHow Has This Been Tested?
New specs. Each one fails without the fix:
IgxStylesRegistrar› register › with a host (7 specs)host)shadowRoot.adoptedStyleSheetsigx-grid-cellisdisplay: flexstartIndex10,TypeError: Cannot read properties of null (reading 'scrollTop')startIndex50TypeError ... (reading 'value')The grid specs use a new
IgxGridInShadowRootComponentingrid-samples.spec.ts. It renders the grid inside@ifin aShadowDomcomponent and copies the styles of the page into its shadow root.The two existing "scroll throttle trailing edge" specs sent
{ target: { scrollTop } }objects throughscrollNotify. They now setscrollTopon the scroll element through a stub, which keeps them free of native scroll events.npm run test:lib: 7675 of 7676 pass. The one failure, a tooltip integration spec, passes when its file runs alone (66 of 66).npm run test:elements: 99 of 99.npm run lint:lib: 0 errors.Test Configuration:
Checklist:
CHANGELOG.MDupdates for newly added functionality